<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:yui="http://yuilibrary.com/rdf/1.0/yui.rdf#">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<title>API: CWN2   layerFactory.js  (YUI Library)</title>

	<link rel="stylesheet" type="text/css" href="assets/reset-fonts-grids-min.css?stamp=1308058435.87" />
	<link rel="stylesheet" type="text/css" href="assets/api.css?stamp=1308058435.87" />

    <script type="text/javascript" src="assets/api-js?stamp=1308058435.87"></script>
    <script type="text/javascript" src="assets/ac-js?stamp=1308058435.87"></script>
</head>

<body id="yahoo-com">

<div id="doc3" class="yui-t2">
	<div id="hd">
        <h1><a href="/CartoWebNet2/lib/Cwn2/" title="CartoWebNet2 Javascript Library">CartoWebNet2 Javascript Library</a></h1>
        <h3>CWN2&nbsp; <span class="subtitle">1.0.0</span></h3>
        <a href="./index.html" title="CartoWebNet2 Javascript Library">CartoWebNet2 Javascript Library</a> 
            &gt; <a href="./module_cwn2.html" title="CWN2">CWN2</a>
                
                 &gt; layerFactory.js (source view) 
        <form onsubmit="return false">
            <div id="propertysearch">
                Search: <input autocomplete="off" id="searchinput" />
                <div id="searchresults">
                    &nbsp;
                </div>
            </div>
        </form>
	</div>

	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">
            <form action="#" name="yui-classopts-form" method="get" id="yui-classopts-form">
                <fieldset>
                    <legend>Filters</legend>
                <span class="classopts"><input type="checkbox" name="show_private" id="show_private" /> <label for="show_private">Show Private</label></span>
                <span class="classopts"><input type="checkbox" name="show_protected" id="show_protected" /> <label for="show_protected">Show Protected</label></span>
                <span class="classopts"><input type="checkbox" name="show_deprecated" id="show_deprecated" /> <label for="show_deprecated">Show Deprecated</label></span>
                </fieldset>
            </form>

                    <div id="srcout">
                        <style>
                            #doc3 .classopts { display:none; }
                        </style>
<div class="highlight"><pre><span class="c1">//#include &lt;base.js&gt;</span>
<span class="c1">//#include &lt;openlayersExt.js&gt;</span>
<span class="c1">//#include &lt;event.js&gt;</span>


<span class="cm">/**</span>
<span class="cm">* </span>
<span class="cm">* Factory per creazione di layers di tipo OL</span>
<span class="cm">* </span>
<span class="cm">* @namespace CWN2</span>
<span class="cm">* @class layerFactory</span>
<span class="cm">* </span>
<span class="cm">*/</span>

<span class="nx">CWN2</span><span class="p">.</span><span class="nx">layerFactory</span> <span class="o">=</span> <span class="p">{</span>

	<span class="cm">/**</span>
<span class="cm">	* </span>
<span class="cm">	* Create an OpenLayers layer based on a given configuration</span>
<span class="cm">	* </span>
<span class="cm">	* @method createLayer</span>
<span class="cm">	* </span>
<span class="cm">	* @param {layerConfig} layerConfig Obj containing the layer configuration </span>
<span class="cm">	* </span>
<span class="cm">	* @return: 	{OpenLayers.Layer}</span>
<span class="cm">	* </span>
<span class="cm">	*/</span> 
	
	<span class="nx">createLayer</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">layerConfig</span><span class="p">)</span> <span class="p">{</span>

		<span class="k">if</span> <span class="p">(</span><span class="nx">CWN2</span><span class="p">.</span><span class="nx">base</span><span class="p">.</span><span class="nx">DEBUG</span><span class="p">)</span> <span class="p">{</span>
			<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;CWN2.layerFactory.createLayer&#39;</span><span class="p">);</span>
		<span class="p">}</span>
		<span class="k">return</span> <span class="nx">CWN2</span><span class="p">.</span><span class="nx">layerFactory</span><span class="p">[</span><span class="nx">layerConfig</span><span class="p">.</span><span class="nx">type</span><span class="p">](</span><span class="nx">layerConfig</span><span class="p">);</span>
	
	<span class="p">},</span>
	
	<span class="cm">/*</span>
<span class="cm">	* </span>
<span class="cm">    * Metodi per creazione dei layer Openlayers dei vari tipi</span>
<span class="cm">    *</span>
<span class="cm">    */</span> 
    
    <span class="c1">// google stradario</span>
	<span class="nx">google_roadmap</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">layerConfig</span><span class="p">)</span> <span class="p">{</span>
		<span class="k">if</span> <span class="p">(</span><span class="nx">CWN2</span><span class="p">.</span><span class="nx">base</span><span class="p">.</span><span class="nx">DEBUG</span><span class="p">)</span> <span class="p">{</span>
			<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;google_roadmap&#39;</span><span class="p">);</span>
		<span class="p">}</span>
		<span class="kd">var</span> <span class="nx">layerType</span> <span class="o">=</span> <span class="nx">google</span><span class="p">.</span><span class="nx">maps</span><span class="p">.</span><span class="nx">MapTypeId</span><span class="p">.</span><span class="nx">ROADMAP</span><span class="p">;</span>
		<span class="k">return</span> <span class="nx">CWN2</span><span class="p">.</span><span class="nx">layerFactory</span><span class="p">.</span><span class="nx">google</span><span class="p">(</span><span class="nx">layerType</span><span class="p">,</span><span class="nx">layerConfig</span><span class="p">);</span>
	<span class="p">},</span>
	
    <span class="c1">// google satellite</span>
	<span class="nx">google_satellite</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">layerConfig</span><span class="p">)</span> <span class="p">{</span>
		<span class="k">if</span> <span class="p">(</span><span class="nx">CWN2</span><span class="p">.</span><span class="nx">base</span><span class="p">.</span><span class="nx">DEBUG</span><span class="p">)</span> <span class="p">{</span>
			<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;google_satellite&#39;</span><span class="p">);</span>
		<span class="p">}</span>
		<span class="kd">var</span> <span class="nx">layerType</span> <span class="o">=</span> <span class="nx">google</span><span class="p">.</span><span class="nx">maps</span><span class="p">.</span><span class="nx">MapTypeId</span><span class="p">.</span><span class="nx">SATELLITE</span><span class="p">;</span>
		<span class="k">return</span> <span class="nx">CWN2</span><span class="p">.</span><span class="nx">layerFactory</span><span class="p">.</span><span class="nx">google</span><span class="p">(</span><span class="nx">layerType</span><span class="p">,</span><span class="nx">layerConfig</span><span class="p">);</span>
	<span class="p">},</span>
	
	<span class="c1">// google generico</span>
	<span class="nx">google</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">layerType</span><span class="p">,</span><span class="nx">layerConfig</span><span class="p">)</span> <span class="p">{</span>
		<span class="kd">var</span>	<span class="nx">olLayer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Layer</span><span class="p">.</span><span class="nx">Google</span><span class="p">(</span>
			<span class="nx">layerConfig</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span>
			<span class="p">{</span>
				<span class="nx">type</span><span class="o">:</span> <span class="nx">layerType</span><span class="p">,</span>
				<span class="nx">minZoomLevel</span><span class="o">:</span> <span class="nx">layerConfig</span><span class="p">.</span><span class="nx">minZoomLevel</span><span class="p">,</span> 
				<span class="nx">maxZoomLevel</span><span class="o">:</span> <span class="nx">layerConfig</span><span class="p">.</span><span class="nx">maxZoomLevel</span> 
			<span class="p">}</span>
		<span class="p">);</span>
		<span class="k">return</span> <span class="nx">olLayer</span><span class="p">;</span>
	<span class="p">},</span>
	
	<span class="c1">// Vettoriale GeoJSON</span>
	<span class="nx">GeoJSON</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">layerConfig</span><span class="p">)</span> <span class="p">{</span>
		<span class="k">if</span> <span class="p">(</span><span class="nx">CWN2</span><span class="p">.</span><span class="nx">base</span><span class="p">.</span><span class="nx">DEBUG</span><span class="p">)</span> <span class="p">{</span>
			<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;GeoJSON&#39;</span><span class="p">);</span>
		<span class="p">}</span>
		<span class="kd">var</span> <span class="nx">layerOptions</span> <span class="o">=</span> <span class="p">{};</span>
		<span class="nx">layerOptions</span><span class="p">.</span><span class="nx">projection</span> <span class="o">=</span> <span class="nx">layerConfig</span><span class="p">.</span><span class="nx">projection</span> <span class="o">||</span> <span class="s1">&#39;EPSG:900913&#39;</span><span class="p">;</span>
		<span class="k">if</span> <span class="p">(</span><span class="nx">layerConfig</span><span class="p">.</span><span class="nx">url</span> <span class="o">!==</span> <span class="kc">undefined</span><span class="p">){</span>
			<span class="nx">layerOptions</span><span class="p">.</span><span class="nx">protocol</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Protocol</span><span class="p">.</span><span class="nx">HTTP</span><span class="p">({</span>
					<span class="nx">url</span><span class="o">:</span> <span class="nx">layerConfig</span><span class="p">.</span><span class="nx">url</span><span class="p">,</span>
					<span class="nx">format</span><span class="o">:</span> <span class="k">new</span> <span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Format</span><span class="p">.</span><span class="nx">GeoJSON</span><span class="p">({})</span>
				<span class="p">});</span>
			<span class="nx">layerOptions</span><span class="p">.</span><span class="nx">strategies</span> <span class="o">=</span> <span class="nx">layerConfig</span><span class="p">.</span><span class="nx">strategies</span> <span class="o">||</span> <span class="p">[</span><span class="k">new</span> <span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Strategy</span><span class="p">.</span><span class="nx">Fixed</span><span class="p">()];</span>
	
		<span class="p">}</span>
		<span class="kd">var</span> <span class="nx">olLayer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Layer</span><span class="p">.</span><span class="nx">Vector</span><span class="p">(</span>
			<span class="nx">layerConfig</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span>
			<span class="nx">layerOptions</span>
		<span class="p">);</span>
		<span class="c1">// gestione stile</span>
		<span class="k">if</span> <span class="p">(</span><span class="nx">layerConfig</span><span class="p">.</span><span class="nx">styleMap</span> <span class="o">!==</span> <span class="kc">undefined</span><span class="p">){</span>
			<span class="nx">olLayer</span><span class="p">.</span><span class="nx">styleMap</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">StyleMap</span><span class="p">(</span><span class="nx">layerConfig</span><span class="p">.</span><span class="nx">styleMap</span><span class="p">);</span>			
		<span class="p">}</span>
		<span class="k">return</span> <span class="nx">olLayer</span><span class="p">;</span>
	<span class="p">}</span>

<span class="p">};</span>
</pre></div>
                    </div>
			</div>
		</div>
		<div class="yui-b">
            <div class="nav">

                    <div id="moduleList" class="module">
                        <h4>Modules</h4>
                        <ul class="content">
                                <li class="selected"><a href="module_CWN2.html" title="CWN2">CWN2</a></li>
                        </ul>
                    </div>

                    <div id="classList" class="module">
                        <h4>Classes</h4>
                        <ul class="content">
                                <li class=""><a href="CWN2.configuration.html" title="CWN2.configuration">CWN2.configuration</a></li>
                                <li class=""><a href="CWN2.event.html" title="CWN2.event">CWN2.event</a></li>
                                <li class=""><a href="CWN2.json.html" title="CWN2.json">CWN2.json</a></li>
                                <li class=""><a href="CWN2.layerFactory.html" title="CWN2.layerFactory">CWN2.layerFactory</a></li>
                                <li class=""><a href="CWN2.Map.html" title="CWN2.Map">CWN2.Map</a></li>
                        </ul>
                    </div>

                    <div id="fileList" class="module">
                        <h4>Files</h4>
                        <ul class="content">        
                                <li class=""><a href="base.js.html" title="base.js">base.js</a></li>
                                <li class=""><a href="configuration.js.html" title="configuration.js">configuration.js</a></li>
                                <li class=""><a href="event.js.html" title="event.js">event.js</a></li>
                                <li class=""><a href="json.js.html" title="json.js">json.js</a></li>
                                <li class="selected"><a href="layerFactory.js.html" title="layerFactory.js">layerFactory.js</a></li>
                                <li class=""><a href="Map.js.html" title="Map.js">Map.js</a></li>
                                <li class=""><a href="openlayersExt.js.html" title="openlayersExt.js">openlayersExt.js</a></li>
                        </ul>
                    </div>





            </div>
		</div>
	</div>
	<div id="ft">
        <hr />
        Copyright &copy; 2011 Yahoo! Inc. All rights reserved.
	</div>
</div>
<script type="text/javascript">
    ALL_YUI_PROPS = [{"url": "CWN2.Map.html#method_activateSelectFeatureControl", "access": "", "host": "CWN2.Map", "type": "method", "name": "activateSelectFeatureControl"}, {"url": "CWN2.configuration.html#property_buttons", "access": "", "host": "CWN2.configuration", "type": "property", "name": "buttons"}, {"url": "CWN2.configuration.html#property_controls", "access": "", "host": "CWN2.configuration", "type": "property", "name": "controls"}, {"url": "CWN2.layerFactory.html#method_createLayer", "access": "", "host": "CWN2.layerFactory", "type": "method", "name": "createLayer"}, {"url": "CWN2.configuration.html#method_getLayerConfigByName", "access": "", "host": "CWN2.configuration", "type": "method", "name": "getLayerConfigByName"}, {"url": "CWN2.configuration.html#property_layers", "access": "", "host": "CWN2.configuration", "type": "property", "name": "layers"}, {"url": "CWN2.configuration.html#property_layout", "access": "", "host": "CWN2.configuration", "type": "property", "name": "layout"}, {"url": "CWN2.configuration.html#method_load", "access": "", "host": "CWN2.configuration", "type": "method", "name": "load"}, {"url": "CWN2.json.html#method_load", "access": "", "host": "CWN2.json", "type": "method", "name": "load"}, {"url": "CWN2.json.html#method_loadAsync", "access": "", "host": "CWN2.json", "type": "method", "name": "loadAsync"}, {"url": "CWN2.Map.html#method_loadConfig", "access": "", "host": "CWN2.Map", "type": "method", "name": "loadConfig"}, {"url": "CWN2.Map.html#method_loadLayer", "access": "", "host": "CWN2.Map", "type": "method", "name": "loadLayer"}, {"url": "CWN2.Map.html#method_loadLayers", "access": "", "host": "CWN2.Map", "type": "method", "name": "loadLayers"}, {"url": "CWN2.configuration.html#property_mapOptions", "access": "", "host": "CWN2.configuration", "type": "property", "name": "mapOptions"}, {"url": "CWN2.configuration.html#property_name", "access": "", "host": "CWN2.configuration", "type": "property", "name": "name"}, {"url": "CWN2.event.html#method_onFeatureSelect", "access": "", "host": "CWN2.event", "type": "method", "name": "onFeatureSelect"}, {"url": "CWN2.event.html#method_onFeatureUnselect", "access": "", "host": "CWN2.event", "type": "method", "name": "onFeatureUnselect"}];
</script>
</body>
</html>
